package com.ant.collect.controller;


import com.ant.collect.common.ResultVo;
import com.ant.collect.pojo.Role;
import com.ant.collect.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hzd
 * @since 2025-11-03
 */
@RestController
@RequestMapping("/role")
public class RoleController {

     @Autowired
     IRoleService roleService;

    /**
     * 分页查询所有角色数据
     * @param
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public ResultVo queryRoleListByPage(@PathVariable("pageNo") Integer pageNo,
                                        @PathVariable("pageSize") Integer pageSize,
                                        String roleName) {
        Map<String,Object> map = roleService.queryRoleListByPage(pageNo,pageSize,roleName);
        return ResultVo.success(map);
    }

    /**
     * 查询所有角色数据
     * @param
     * @return
     */
    @GetMapping("/list")
    public ResultVo queryRoleList() {
        List<String> roleList = roleService.queryRoleList();
        return ResultVo.success(roleList);
    }

    /**
     * 新增角色
     * @param
     * @return
     */
    @PostMapping("/save")
    public ResultVo saveRole(@RequestBody Role role) {
        roleService.save(role);
        return ResultVo.success();
    }

    /**
     * 分配权限
     * @param
     * @return
     */
    @PostMapping("/save/permission/{roleId}")
    public ResultVo savePermission(@PathVariable("roleId") Integer roleId,
                                     @RequestBody List<Integer> menuIds) {
        roleService.savePermission(roleId,menuIds);
        return ResultVo.success();
    }
}
